angular.module('app').factory('serverService', ['$http', 'localStorageService' ,function($http,localStorageService) {
    //服务器地址
    var graphUrl = {
        //serverLocal : "http://localhost:7474"
        serverLocal : ""
    };

    var serverService = {
        host: graphUrl.serverLocal,
        settings : {
            endpoint: {
                console: graphUrl.serverLocal + "/db/manage/server/console",
                version: graphUrl.serverLocal + "/db/manage/server/version",
                jmx: graphUrl.serverLocal + "/db/manage/server/jmx/query",
                rest: graphUrl.serverLocal + "/db/data",
                cypher: graphUrl.serverLocal + "/db/data" + "/cypher",
                transaction: graphUrl.serverLocal + "/db/data" + "/transaction",
                authUser: graphUrl.serverLocal + "/user",
                export: graphUrl.serverLocal + "/db/data/export",
                import: graphUrl.serverLocal + "/db/data/import",
                getBackupData: graphUrl.serverLocal + "/db/data/backuprestore/",
                backup:graphUrl.serverLocal + "/db/data/backuprestore/backup",
                delbackup:graphUrl.serverLocal + "/db/data/backuprestore/"
            }
        },
        returnHeaders : function(){
            var headers = {};
            return headers;
        },
        loadSettings :function(){
            var settings = this.settings;
            var originalSettings = angular.copy(settings);
            localStorageService.set('Settings', originalSettings);
        },
    	//发送请求
    	sendPost: function(url,data,suc,err){
            var headers = this.returnHeaders();
            if(err){
                $http.post(url,data,{headers:headers}).success(suc).error(err);
            }else{
                $http.post(url,data,{headers:headers}).success(suc);
            }
    		
    	},
        //send delete
        sendDelete: function(url,data,suc,err){
            var headers = this.returnHeaders();
            if(err){
                $http.delete(url,{headers:headers}).success(suc).error(err);
            }else{
                $http.delete(url,{headers:headers}).success(suc);
            }
            
        },
        sendGet: function(url,suc,err){
            var headers = this.returnHeaders();
            if(err){
                $http.get(url,{headers:headers}).success(suc).error(err);
            }else{
                $http.get(url,{headers:headers}).success(suc);
            }
            
        }
    };
    return serverService;
}]);